
	/** *************定义学生列表数据************ */
	var graduateManageProxy = new Ext.data.HttpProxy({url: "graduate/graduateListAction!deanExecute.action"});
	var graduate = Ext.data.Record.create([
		{name: "id", type: "int", mapping: "id"},
		{name: "number", type: "string", mapping: "number"},
		{name: "gender", type: "string", mapping: "gender"},
		{name: "name", type: "string", mapping: "name"},
		{name: "paperState", type: "string", mapping: "paper",convert:function(v){return v?v.strState:"未提交论文";}}
		//{name: "email", type: "string", mapping: "email"}
	]);
	var graduateManageReader = new Ext.data.JsonReader(
		{totalProperty: "totalProperty", root: "root"},
		graduate
	);
	var graduateManageStore = new Ext.data.Store({
		proxy: graduateManageProxy,
		reader: graduateManageReader
		// autoLoad:true
	});
	
	/** ***************定义行列模型***************** */
	// 行模型
	var sm = new Ext.grid.CheckboxSelectionModel(
		// {singleSelect: true}
	);
	// 列模型
	var cm = new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer(),
		sm,
		{header: "学生编号", width: 100, dataIndex: "number",sortable:true},
		{header: "姓名", width: 80,dataIndex: "name",sortable:true},
		{header: "性别", width: 80,dataIndex: "gender",sortable:true},
		{header: "论文状态", width: 80,dataIndex: "paperState",sortable:true}
		//{header: "邮箱", width: 150, dataIndex: "email"}
	]);
	
	/** ***************定义面板的topBar和bottomBar***************** */
	var addBtn = new Ext.Button({
		text:"添加",
		tooltip:"添加一个学生",
		id:"addBtn",
		iconCls:'icon-btn-add',
		handler:function(){
			new addOrModifyFn('graduate/graduateAddAction');
		}
	});
	
	var deleteBtn = new Ext.Button({
		text:"删除",
		tooltip:"删除学生信息",
		id:"deleteBtn",
		iconCls:'x-btn-text-icon',
		handler:function(){
			new deleteFn();
		}
	});
	
	var modifyBtn = new Ext.Button({
		text:'编辑',
		tooltip:'编辑学生信息',
		iconCls:'icon-btn-edit',
		handler:function(){
			var _selectModel = graduateManageGrid.getSelectionModel();
			if(!_selectModel.hasSelection()){
				Ext.Msg.alert("","请选择要编辑的行");			
				// new addOrModifyFn('dept!modify',_rec.get('id'));
				
			} else if(_selectModel.getSelections().length > 1){
				Ext.Msg.alert("","一次只能编辑一行");	
			}else {
				var _rec = _selectModel.getSelected();	
				// Ext.example.msg("警告","编辑前请选择一条记录……","msg-box-error");
				new addOrModifyFn('graduate/graduateModifyAction',_rec.get('id'));
			}
			
		}
	});
	
	var bbar = new Ext.PagingToolbar({
		store: graduateManageStore,
		pageSize: 10,// 页大小
		displayInfo: true,// 是否显示displayMsg
		displayMsg: "第{0}条到第{1}条,共{2}条",
		emptyMsg: "没有记录"// 如果没有记录，则显示该文本
	});
	
	/** ***************定义主体panel***************** */
	var graduateManageGrid = new Ext.grid.GridPanel({
		region:'center',
		closable:true,
		//title: "学生列表",
		width: 400,
		frame:true,		
		cm: cm,
		sm: sm,
		store: graduateManageStore,
		tbar:[addBtn,"-",modifyBtn,"-",deleteBtn],
		bbar:bbar
	});		
	
	//添加双击某行弹出编辑框的响应
	graduateManageGrid.on('rowdblclick',function(grid,index,e){
		var _rec = graduateManageGrid.store.getAt(index);//取出点击的那条记录
		new addOrModifyFn('graduate/graduateModifyAction',_rec.get('id'));
	});
	
	/** ***************定义添加/修改学生处理表格以及窗口******************* */
	var graduateInfoForm = new Ext.form.FormPanel({
		id:"graduateInfoForm",
		frame:true,
		bodyStyle:"padding:5px 5px 0",
		border:false,
		waitMsgTarget:true,// true的意思是说表单提交时的等待信息在这个表单之内显示，而不是弹出框(进度条形式的)
		labelAlign:"right",
		labelPad : 10,// 标签与字段录入框之间的空白
		defaults:{width:230/*,disabled:true*/},
		defaultType:"textfield",
		items:[{
				xtype:"hidden",
				name:"graduate.id",
				value:0
				},{
				fieldLabel:"姓名",
				name:"graduate.name",
				allowBlank:false,
				emptyText:"填写学生姓名"
			},{
				fieldLabel:"学号",
				name:"graduate.number",
				allowBlank:false,
				emptyText:"填写学号"
			},{
				xtype:"combo",
				hiddenName:"graduate.gender",
				fieldLabel:"性别",
				store:new Ext.data.SimpleStore({
						fields: ['value','display'],
						data: [["男","男"],["女","女"]]
					}),
				triggerAction: 'all',
				displayField:"display",
				valueField:"value",
				mode:"local",
				//readOnly:true,
				allowBlank:false,
				emptyText:"选择性别"
			}]
	});
	
	/** *****************提交修改表单处理函数********************* */
	var addOrModifyCommitFn = function(_url){
		if(Ext.getCmp("graduateInfoForm").getForm().isValid()){// 对表单进行验证(根据配置的项进行配置)
			Ext.getCmp("graduateInfoForm").getForm().submit({// 利用表单的submit方法提交表单
				waitTitle:"请稍候",					// 提交表单时进度条的标题
				waitMsg:"正在提交数据，请稍后……",		// 提交表单时进度条的信息
				url:_url,							// 提交地址
				method:"POST",						// 提交方式，需要大写
				success:function(form, action){		// 如果提交成功后处理的方法
					//Ext.Msg.alert("提交成功", "提交学生信息成功","msg-box-success");// 相应的提示信息
					// Ext.getCmp("addOrModifyWin").close();
					// //根据id获取到表单的窗口，然后将其关闭
					graduateManageGrid.getStore().reload();				// 提交成功后，需要刷新GridPanel数据，
					Ext.getCmp("addOrModifyWin").close();										// 但效率时会将提交表单中的数据直接添加或更新到GridPanel中
				},
				failure:function(form,action){			// 提交指失败进处理的方法
					Ext.Msg.alert("警告","数据提交失败，请核对","msg-box-error");
				}								
			});	
			
		} else {// 如果表单验证未通过则提示用户骓未通过。
			Ext.Msg.alert("提示","请填写完整、合法的信息","msg-box-error");
		}		
	}
	
	// 显示窗口，如果是修改数据，则需要载入学生原数据
	var addOrModifyFn = function(_url, _id){
		new Ext.Window({
			id:"addOrModifyWin",
			// iconCls:xxx,
			// title:'添加学生',
			// x:100,
			// y:100,
			width:400,
			autoHeight:true,
			resizable:false,// 不可以调整大小
			draggable:false,// 不可移动
			modal:true,// 设置此Window为模式窗口,
			animateTarget:'addBtn',// 当指定一个id或元素,window打开时会与元素之间产生动画效果
			items:[
				new Ext.form.FormPanel(graduateInfoForm)
			],
			buttonAlign:'center',
			minButtonWidth:60,
			buttons:[{
				text:"提交",
				tooltip:"提交数据",
				handler:function(){new addOrModifyCommitFn(_url);}
			},{
				text:"取消",
				tooltip:"取消此操作",
				handler:function(){
					Ext.getCmp("addOrModifyWin").close();// 取消实际上就是关闭窗口
				}
			}]			
		}).show();
		
		if(_id){
			var _form = Ext.getCmp("graduateInfoForm").getForm();
			_form.reader =  new Ext.data.JsonReader({
									root:'graduate'
								},[
							       {name:"graduate.id",type:"int",mapping:"id"},
							       {name:"graduate.number",type:"string",mapping:"number"},
							       {name:"graduate.name",type:"string",mapping:"name"},
							       {name:"graduate.gender",type:"string",mapping:"gender"}
							    //   {name:"graduate.email",type:"string",mapping:"email"}
							    ]);
			_form.load({url:"graduate/graduateInfoAction",
						params: {id: _id},
						waitMsg: '正在载入数据...',
						method:'POST',
						success:function(form, action){
							// Ext.example.msg("提示","数据加载成功……","msg-box-success");
						},
						failure:function(){
							Ext.example.msg("异常","数据加载失败","msg-box-error");
							Ext.getCmp("addOrModifyWin").close();
						}						
					});
		}
	}
	
	var deleteFn = function(){
		var selModel = graduateManageGrid.getSelectionModel();
			if(selModel.hasSelection()){
				Ext.Msg.confirm("确认", "您确定要删除选择的记录吗?",
					function(btn){
						if(btn == "yes"){
							var records = selModel.getSelections();
							var ids = [];
							for(var i = 0; i < records.length; i ++){
								ids.push(records[i].get("id"));
							}
							Ext.Ajax.request({
								url: "graduate/graduateRemoveAction",
								params: {ids: ids},
								waitTitle:"请稍候",	
								waitMsg:"正在处理，请稍后……",	
								method: "post",
								success: function(){
									graduateManageStore.remove(records);
									
									//Ext.MessageBox.alert("成功","删除成功");
								},
								failure: function(){
									Ext.Msg.alert("失败", "对不起,删除失败!!!!!");
								}
							});
							//graduateManageStore.reload();
							//graduateManageStore.reload();
						}
					}//function btn 结束
				)}else{
					Ext.Msg.alert("错误", "请选择要删除的行!");
				}
		}
	Ext.onReady(function(){	
	
		Ext.BLANK_IMAGE_URL = "extjs/resources/images/default/s.gif";
	
		Ext.QuickTips.init();	
		
		var viewPort = new Ext.Viewport({
				layout : 'fit',
				items : [graduateManageGrid]　　　            
			});
		graduateManageStore.load({params: {start: 0, limit: 10}});		
	});